package thinker.miracle.ams.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import thinker.miracle.ams.dao.ParamsDao;
import thinker.miracle.ams.entity.ParamsEntity;
import thinker.miracle.ams.model.ParamsModel;
import thinker.miracle.utils.BeanUtil;


/**
 * @author bo.chen
 *
 */
@Service
public class ParamsService {
	
	@Autowired
	ParamsDao paramsDao;

	/**
	 * 保存
	 * 
	 * @param paramsEntity
	 *
	 */
	@Transactional
	public void save(ParamsEntity paramsEntity){
		if(paramsEntity != null && paramsEntity.getId() == 0){
			paramsDao.insert(paramsEntity);
		}else if(paramsEntity != null && paramsEntity.getId() > 0){
			paramsDao.updateSelective(paramsEntity);
		}else if(paramsEntity == null)
			throw new RuntimeException("null piont exception");
	}
	
	/**
	 * <p> 获取 参数</p>
	 * 
	 * @param interfaceId
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * 
	 */
	public List<ParamsModel> getByInterfaceId(int interfaceId) throws InstantiationException, IllegalAccessException{
		List<ParamsEntity> paramsEntitys = paramsDao.findByInterfaceId(interfaceId);
		return BeanUtil.copyPropertiesList(paramsEntitys, ParamsModel.class);
	}
}